package com.weds.frame.core.autoConfiguration.filter;

import com.weds.frame.core.filter.RequestFilter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2023/3/28 15:54
 */
@Configuration
public class WebFilterConfig {

    @Value("${encry.exclude-path}")
    private String excludePath;

    @Bean
    public FilterRegistrationBean webFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new RequestFilter());
        registration.addUrlPatterns(StringUtils.split("/*", ","));
        registration.setName("requestFilter");
        registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
        Map<String, String> initParameters = new HashMap<String, String>();
        initParameters.put("excludePath", excludePath);
        registration.setInitParameters(initParameters);
        return registration;
    }
}
